package com.xx.job.service.system.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xx.job.common.PageResult;
import com.xx.job.controller.dto.PageDTO;
import com.xx.job.entity.system.SysCategory;
import com.xx.job.mapper.SysCategoryMapper;
import com.xx.job.service.system.SysCategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liangcy
 * @since 2021-01-14
 */
@Service
public class SysCategoryServiceImpl extends ServiceImpl<SysCategoryMapper, SysCategory> implements SysCategoryService {

    @Autowired
    private SysCategoryMapper sysCategoryMapper;

    @Override
    public int add(SysCategory sysCategory) {
        return sysCategoryMapper.insert(sysCategory);
    }

    @Override
    public int delete(Long id) {
        return sysCategoryMapper.deleteById(id);
    }

    @Override
    public int update(SysCategory sysCategory) {
        return sysCategoryMapper.updateById(sysCategory);
    }

    @Override
    public SysCategory select(Long id) {
        return sysCategoryMapper.selectById(id);
    }

    @Override
    public PageResult selectPage(PageDTO pageDTO, SysCategory sysCategory) {
        IPage<SysCategory> page = new Page<>();
        QueryWrapper<SysCategory> wrapper = new QueryWrapper<>();
        if(StringUtils.isNotBlank(sysCategory.getName())){
            wrapper.like("name",sysCategory.getName().trim());
        }
        IPage<SysCategory> sysCategoryIPage = sysCategoryMapper.selectPage(page, wrapper);
        return new PageResult(sysCategoryIPage);
    }
}
